package com.hbnu.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hbnu.mapper.OrderMapper;
import com.hbnu.pojo.Orders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class OrderService{

    @Autowired
    private OrderMapper orderMapper;

     
    //获取当前用户订单
    public List<Orders> getOrderByUserId(Integer userId) {
        LambdaQueryWrapper<Orders> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Orders::getUserId, userId);
        return orderMapper.selectList(wrapper);
    }

    //获取全部订单
    public List<Orders> getOrderByAll() {
        return orderMapper.selectList(null);
    }

    //删除订单
    public boolean deleteOrder(Integer id) {
        return orderMapper.deleteById(id) > 0;
    }

    //修改订单
    public boolean updateOrder(Orders orders) {
        return orderMapper.updateById(orders) > 0;
    }

    //分页查询
    public IPage<Orders> getOrderPage(Page<Orders> page, LambdaQueryWrapper<Orders> wrapper) {
        return orderMapper.selectPage(page, wrapper);
    }

    //查询
    public List<Orders> list(LambdaQueryWrapper<Orders> wrapper) {
        return orderMapper.selectList(wrapper);
    }
}


